home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / oleo-1_4.lha / oleo-1.4 / getdate.c < prev    next >
C/C++ Source or Header  |  1993-05-11  |  47KB  |  1,860 lines

  1.  
  2. /*  A Bison parser, made from getdate.y  */
  3.  
  4. #define YYBISON 1  /* Identify Bison output.  */
  5.  
  6. #define    tAGO    258
  7. #define    tDAY    259
  8. #define    tDAYZONE    260
  9. #define    tID    261
  10. #define    tMERIDIAN    262
  11. #define    tMINUTE_UNIT    263
  12. #define    tMONTH    264
  13. #define    tMONTH_UNIT    265
  14. #define    tSEC_UNIT    266
  15. #define    tSNUMBER    267
  16. #define    tUNUMBER    268
  17. #define    tZONE    269
  18. #define    tDST    270
  19.  
  20. #line 1 "getdate.y"
  21.  
  22. /* $Revision: 2.1 $
  23. **
  24. **  Originally written by Steven M. Bellovin <smb@research.att.com> while
  25. **  at the University of North Carolina at Chapel Hill.  Later tweaked by
  26. **  a couple of people on Usenet.  Completely overhauled by Rich $alz
  27. **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
  28. **  send any email to Rich.
  29. **
  30. **  This grammar has eight shift/reduce conflicts.
  31. **
  32. **  This code is in the public domain and has no copyright.
  33. */
  34. /* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */
  35. /* SUPPRESS 288 on gtderrlab *//* Label unused */
  36.  
  37. #ifdef HAVE_CONFIG_H
  38. #include "config.h"
  39. #endif
  40.  
  41. #ifdef __GNUC__
  42. #define alloca __builtin_alloca
  43. #else
  44. #ifdef HAVE_ALLOCA_H
  45. #include <alloca.h>
  46. #else
  47. #ifdef _AIX /* for Bison */
  48.  #pragma alloca
  49. #else
  50. char *alloca ();
  51. #endif
  52. #endif
  53. #endif
  54.  
  55. #include <stdio.h>
  56. #include <ctype.h>
  57.  
  58. /* The code at the top of get_date which figures out the offset of the
  59.    current time zone checks various CPP symbols to see if special
  60.    tricks are need, but defaults to using the gettimeofday system call.
  61.    Include <sys/time.h> if that will be used.  */
  62.  
  63. #if !defined (USG) && !defined (sgi) && !defined (__386BSD__)
  64. #include <sys/time.h>
  65. #endif
  66.  
  67. #if    defined(vms)
  68.  
  69. #include <types.h>
  70. #include <time.h>
  71.  
  72. #else
  73.  
  74. #include <sys/types.h>
  75.  
  76. #if    defined(USG) || !defined(HAVE_FTIME)
  77. /*
  78. **  If you need to do a tzset() call to set the
  79. **  timezone, and don't have ftime().
  80. */
  81. struct timeb {
  82.     time_t        time;        /* Seconds since the epoch    */
  83.     unsigned short    millitm;    /* Field not used        */
  84.     short        timezone;
  85.     short        dstflag;    /* Field not used        */
  86. };
  87.  
  88. #else
  89.  
  90. #include <sys/timeb.h>
  91.  
  92. #endif    /* defined(USG) && !defined(HAVE_FTIME) */
  93.  
  94. #if    defined(BSD4_2) || defined(BSD4_1C) || (defined (hp9000) && !defined (hpux))
  95. #include <sys/time.h>
  96. #else
  97. #if defined(_AIX)
  98. #include <sys/time.h>
  99. #endif
  100. #include <time.h>
  101. #endif    /* defined(BSD4_2) */
  102.  
  103. #endif    /* defined(vms) */
  104.  
  105. #if defined (STDC_HEADERS) || defined (USG)
  106. #include <string.h>
  107. #endif
  108.  
  109. #if sgi
  110. #undef timezone
  111. #endif
  112.  
  113. extern struct tm    *localtime();
  114.  
  115. #define gtdparse getdate_gtdparse
  116. #define gtdlex getdate_gtdlex
  117. #define gtderror getdate_gtderror
  118.  
  119. #if    !defined(lint) && !defined(SABER)
  120. static char RCS[] =
  121.     "$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $";
  122. #endif    /* !defined(lint) && !defined(SABER) */
  123.  
  124.  
  125. #define EPOCH        1970
  126. #define HOUR(x)        ((time_t)(x) * 60)
  127. #define SECSPERDAY    (24L * 60L * 60L)
  128.  
  129.  
  130. /*
  131. **  An entry in the lexical lookup table.
  132. */
  133. typedef struct _TABLE {
  134.     char    *name;
  135.     int        type;
  136.     time_t    value;
  137. } TABLE;
  138.  
  139.  
  140. /*
  141. **  Daylight-savings mode:  on, off, or not yet known.
  142. */
  143. typedef enum _DSTMODE {
  144.     DSTon, DSToff, DSTmaybe
  145. } DSTMODE;
  146.  
  147. /*
  148. **  Meridian:  am, pm, or 24-hour style.
  149. */
  150. typedef enum _MERIDIAN {
  151.     MERam, MERpm, MER24
  152. } MERIDIAN;
  153.  
  154.  
  155. /*
  156. **  Global variables.  We could get rid of most of these by using a good
  157. **  union as the yacc stack.  (This routine was originally written before
  158. **  yacc had the %union construct.)  Maybe someday; right now we only use
  159. **  the %union very rarely.
  160. */
  161. static char    *gtdInput;
  162. static DSTMODE    gtdDSTmode;
  163. static time_t    gtdDayOrdinal;
  164. static time_t    gtdDayNumber;
  165. static int    gtdHaveDate;
  166. static int    gtdHaveDay;
  167. static int    gtdHaveRel;
  168. static int    gtdHaveTime;
  169. static int    gtdHaveZone;
  170. static time_t    gtdTimezone;
  171. static time_t    gtdDay;
  172. static time_t    gtdHour;
  173. static time_t    gtdMinutes;
  174. static time_t    gtdMonth;
  175. static time_t    gtdSeconds;
  176. static time_t    gtdYear;
  177. static MERIDIAN    gtdMeridian;
  178. static time_t    gtdRelMonth;
  179. static time_t    gtdRelSeconds;
  180.  
  181.  
  182. #line 163 "getdate.y"
  183. typedef union {
  184.     time_t        Number;
  185.     enum _MERIDIAN    Meridian;
  186. } YYSTYPE;
  187.  
  188. #ifndef YYLTYPE
  189. typedef
  190.   struct gtdltype
  191.     {
  192.       int timestamp;
  193.       int first_line;
  194.       int first_column;
  195.       int last_line;
  196.       int last_column;
  197.       char *text;
  198.    }
  199.   gtdltype;
  200.  
  201. #define YYLTYPE gtdltype
  202. #endif
  203.  
  204. #include <stdio.h>
  205.  
  206. #ifndef __STDC__
  207. #define const
  208. #endif
  209.  
  210.  
  211.  
  212. #define    YYFINAL        51
  213. #define    YYFLAG        -32768
  214. #define    YYNTBASE    19
  215.  
  216. #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? gtdtranslate[x] : 29)
  217.  
  218. static const char gtdtranslate[] = {     0,
  219.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  220.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  221.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  222.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  223.      2,     2,     2,    17,     2,     2,    18,     2,     2,     2,
  224.      2,     2,     2,     2,     2,     2,     2,    16,     2,     2,
  225.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  226.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  227.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  228.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  229.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  230.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  232.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  233.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  234.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  235.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  236.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  237.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  238.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  239.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  240.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  241.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  242.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  243.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  244.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  245.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15
  246. };
  247.  
  248. #if YYDEBUG != 0
  249. static const short gtdprhs[] = {     0,
  250.      0,     1,     4,     6,     8,    10,    12,    14,    16,    19,
  251.     24,    29,    36,    43,    45,    47,    50,    52,    55,    58,
  252.     62,    68,    72,    75,    80,    83,    87,    90,    92,    95,
  253.     98,   100,   103,   106,   108,   111,   114,   116,   118,   119
  254. };
  255.  
  256. #endif
  257.  
  258. static const short gtdrhs[] = {    -1,
  259.     19,    20,     0,    21,     0,    22,     0,    24,     0,    23,
  260.      0,    25,     0,    27,     0,    13,     7,     0,    13,    16,
  261.     13,    28,     0,    13,    16,    13,    12,     0,    13,    16,
  262.     13,    16,    13,    28,     0,    13,    16,    13,    16,    13,
  263.     12,     0,    14,     0,     5,     0,    14,    15,     0,     4,
  264.      0,     4,    17,     0,    13,     4,     0,    13,    18,    13,
  265.      0,    13,    18,    13,    18,    13,     0,    13,    12,    12,
  266.      0,     9,    13,     0,     9,    13,    17,    13,     0,    13,
  267.      9,     0,    13,     9,    13,     0,    26,     3,     0,    26,
  268.      0,    13,     8,     0,    12,     8,     0,     8,     0,    12,
  269.     11,     0,    13,    11,     0,    11,     0,    12,    10,     0,
  270.     13,    10,     0,    10,     0,    13,     0,     0,     7,     0
  271. };
  272.  
  273. #if YYDEBUG != 0
  274. static const short gtdrline[] = { 0,
  275.    177,   178,   181,   184,   187,   190,   193,   196,   199,   205,
  276.    211,   218,   224,   234,   238,   242,   249,   253,   257,   263,
  277.    267,   272,   278,   282,   287,   291,   298,   302,   305,   308,
  278.    311,   314,   317,   320,   323,   326,   329,   334,   362,   365
  279. };
  280.  
  281. static const char * const gtdtname[] = {   "$","error","$illegal.","tAGO","tDAY",
  282. "tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
  283. "tSNUMBER","tUNUMBER","tZONE","tDST","':'","','","'/'","spec","item","time",
  284. "zone","day","date","rel","relunit","number","o_merid",""
  285. };
  286. #endif
  287.  
  288. static const short gtdr1[] = {     0,
  289.     19,    19,    20,    20,    20,    20,    20,    20,    21,    21,
  290.     21,    21,    21,    22,    22,    22,    23,    23,    23,    24,
  291.     24,    24,    24,    24,    24,    24,    25,    25,    26,    26,
  292.     26,    26,    26,    26,    26,    26,    26,    27,    28,    28
  293. };
  294.  
  295. static const short gtdr2[] = {     0,
  296.      0,     2,     1,     1,     1,     1,     1,     1,     2,     4,
  297.      4,     6,     6,     1,     1,     2,     1,     2,     2,     3,
  298.      5,     3,     2,     4,     2,     3,     2,     1,     2,     2,
  299.      1,     2,     2,     1,     2,     2,     1,     1,     0,     1
  300. };
  301.  
  302. static const short gtddefact[] = {     1,
  303.      0,    17,    15,    31,     0,    37,    34,     0,    38,    14,
  304.      2,     3,     4,     6,     5,     7,    28,     8,    18,    23,
  305.     30,    35,    32,    19,     9,    29,    25,    36,    33,     0,
  306.      0,     0,    16,    27,     0,    26,    22,    39,    20,    24,
  307.     40,    11,     0,    10,     0,    39,    21,    13,    12,     0,
  308.      0
  309. };
  310.  
  311. static const short gtddefgoto[] = {     1,
  312.     11,    12,    13,    14,    15,    16,    17,    18,    44
  313. };
  314.  
  315. static const short gtdpact[] = {-32768,
  316.      0,   -15,-32768,-32768,   -10,-32768,-32768,    25,    11,    -8,
  317. -32768,-32768,-32768,-32768,-32768,-32768,    13,-32768,-32768,     7,
  318. -32768,-32768,-32768,-32768,-32768,-32768,     4,-32768,-32768,    14,
  319.     15,    19,-32768,-32768,    24,-32768,-32768,    18,    20,-32768,
  320. -32768,-32768,    26,-32768,    27,    -6,-32768,-32768,-32768,    31,
  321. -32768
  322. };
  323.  
  324. static const short gtdpgoto[] = {-32768,
  325. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5
  326. };
  327.  
  328.  
  329. #define    YYLAST        41
  330.  
  331.  
  332. static const short gtdtable[] = {    50,
  333.     41,    19,    20,     2,     3,    48,    33,     4,     5,     6,
  334.      7,     8,     9,    10,    24,    34,    36,    25,    26,    27,
  335.     28,    29,    30,    35,    41,    37,    31,    38,    32,    42,
  336.     51,    39,    21,    43,    22,    23,    40,    45,    46,    47,
  337.     49
  338. };
  339.  
  340. static const short gtdcheck[] = {     0,
  341.      7,    17,    13,     4,     5,    12,    15,     8,     9,    10,
  342.     11,    12,    13,    14,     4,     3,    13,     7,     8,     9,
  343.     10,    11,    12,    17,     7,    12,    16,    13,    18,    12,
  344.      0,    13,     8,    16,    10,    11,    13,    18,    13,    13,
  345.     46
  346. };
  347. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  348. #line 3 "/afs/andrew/usr11/lord//lib/bison.simple"
  349.  
  350. /* Skeleton output parser for bison,
  351.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  352.  
  353.    This program is free software; you can redistribute it and/or modify
  354.    it under the terms of the GNU General Public License as published by
  355.    the Free Software Foundation; either version 1, or (at your option)
  356.    any later version.
  357.  
  358.    This program is distributed in the hope that it will be useful,
  359.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  360.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  361.    GNU General Public License for more details.
  362.  
  363.    You should have received a copy of the GNU General Public License
  364.    along with this program; if not, write to the Free Software
  365.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  366.  
  367.  
  368. #ifndef alloca
  369. #ifdef __GNUC__
  370. #define alloca __builtin_alloca
  371. #else /* not GNU C.  */
  372. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc)
  373. #include <alloca.h>
  374. #else /* not sparc */
  375. #if defined (MSDOS) && !defined (__TURBOC__)
  376. #include <malloc.h>
  377. #else /* not MSDOS, or __TURBOC__ */
  378. #if defined(_AIX)
  379. #include <malloc.h>
  380.  #pragma alloca
  381. #endif /* not _AIX */
  382. #endif /* not MSDOS, or __TURBOC__ */
  383. #endif /* not sparc.  */
  384. #endif /* not GNU C.  */
  385. #endif /* alloca not defined.  */
  386.  
  387. /* This is the parser code that is written into each bison parser
  388.   when the %semantic_parser declaration is not specified in the grammar.
  389.   It was written by Richard Stallman by simplifying the hairy parser
  390.   used when %semantic_parser is specified.  */
  391.  
  392. /* Note: there must be only one dollar sign in this file.
  393.    It is replaced by the list of actions, each action
  394.    as one case of the switch.  */
  395.  
  396. #define gtderrok        (gtderrstatus = 0)
  397. #define gtdclearin    (gtdchar = YYEMPTY)
  398. #define YYEMPTY        -2
  399. #define YYEOF        0
  400. #define YYACCEPT    return(0)
  401. #define YYABORT     return(1)
  402. #define YYERROR        goto gtderrlab1
  403. /* Like YYERROR except do call gtderror.
  404.    This remains here temporarily to ease the
  405.    transition to the new meaning of YYERROR, for GCC.
  406.    Once GCC version 2 has supplanted version 1, this can go.  */
  407. #define YYFAIL        goto gtderrlab
  408. #define YYRECOVERING()  (!!gtderrstatus)
  409. #define YYBACKUP(token, value) \
  410. do                                \
  411.   if (gtdchar == YYEMPTY && gtdlen == 1)                \
  412.     { gtdchar = (token), gtdlval = (value);            \
  413.       gtdchar1 = YYTRANSLATE (gtdchar);                \
  414.       YYPOPSTACK;                        \
  415.       goto gtdbackup;                        \
  416.     }                                \
  417.   else                                \
  418.     { gtderror ("syntax error: cannot back up"); YYERROR; }    \
  419. while (0)
  420.  
  421. #define YYTERROR    1
  422. #define YYERRCODE    256
  423.  
  424. #ifndef YYPURE
  425. #define YYLEX        gtdlex()
  426. #endif
  427.  
  428. #ifdef YYPURE
  429. #ifdef YYLSP_NEEDED
  430. #define YYLEX        gtdlex(>dlval, >dlloc)
  431. #else
  432. #define YYLEX        gtdlex(>dlval)
  433. #endif
  434. #endif
  435.  
  436. /* If nonreentrant, generate the variables here */
  437.  
  438. #ifndef YYPURE
  439.  
  440. int    gtdchar;            /*  the lookahead symbol        */
  441. YYSTYPE    gtdlval;            /*  the semantic value of the        */
  442.                 /*  lookahead symbol            */
  443.  
  444. #ifdef YYLSP_NEEDED
  445. YYLTYPE gtdlloc;            /*  location data for the lookahead    */
  446.                 /*  symbol                */
  447. #endif
  448.  
  449. int gtdnerrs;            /*  number of parse errors so far       */
  450. #endif  /* not YYPURE */
  451.  
  452. #if YYDEBUG != 0
  453. int gtddebug;            /*  nonzero means print parse trace    */
  454. /* Since this is uninitialized, it does not stop multiple parsers
  455.    from coexisting.  */
  456. #endif
  457.  
  458. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  459.  
  460. #ifndef    YYINITDEPTH
  461. #define YYINITDEPTH 200
  462. #endif
  463.  
  464. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  465.     (effective only if the built-in stack extension method is used).  */
  466.  
  467. #if YYMAXDEPTH == 0
  468. #undef YYMAXDEPTH
  469. #endif
  470.  
  471. #ifndef YYMAXDEPTH
  472. #define YYMAXDEPTH 10000
  473. #endif
  474.  
  475. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  476. #define __gtd_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  477. #else                /* not GNU C or C++ */
  478. #ifndef __cplusplus
  479.  
  480. /* This is the most reliable way to avoid incompatibilities
  481.    in available built-in functions on various systems.  */
  482. static void
  483. __gtd_bcopy (from, to, count)
  484.      char *from;
  485.      char *to;
  486.      int count;
  487. {
  488.   register char *f = from;
  489.   register char *t = to;
  490.   register int i = count;
  491.  
  492.   while (i-- > 0)
  493.     *t++ = *f++;
  494. }
  495.  
  496. #else /* __cplusplus */
  497.  
  498. /* This is the most reliable way to avoid incompatibilities
  499.    in available built-in functions on various systems.  */
  500. static void
  501. __gtd_bcopy (char *from, char *to, int count)
  502. {
  503.   register char *f = from;
  504.   register char *t = to;
  505.   register int i = count;
  506.  
  507.   while (i-- > 0)
  508.     *t++ = *f++;
  509. }
  510.  
  511. #endif
  512. #endif
  513.  
  514. #line 169 "/afs/andrew/usr11/lord//lib/bison.simple"
  515. int
  516. gtdparse()
  517. {
  518.   register int gtdstate;
  519.   register int gtdn;
  520.   register short *gtdssp;
  521.   register YYSTYPE *gtdvsp;
  522.   int gtderrstatus;    /*  number of tokens to shift before error messages enabled */
  523.   int gtdchar1;        /*  lookahead token as an internal (translated) token number */
  524.  
  525.   short    gtdssa[YYINITDEPTH];    /*  the state stack            */
  526.   YYSTYPE gtdvsa[YYINITDEPTH];    /*  the semantic value stack        */
  527.  
  528.   short *gtdss = gtdssa;        /*  refer to the stacks thru separate pointers */
  529.   YYSTYPE *gtdvs = gtdvsa;    /*  to allow gtdoverflow to reallocate them elsewhere */
  530.  
  531. #ifdef YYLSP_NEEDED
  532.   YYLTYPE gtdlsa[YYINITDEPTH];    /*  the location stack            */
  533.   YYLTYPE *gtdls = gtdlsa;
  534.   YYLTYPE *gtdlsp;
  535.  
  536. #define YYPOPSTACK   (gtdvsp--, gtdssp--, gtdlsp--)
  537. #else
  538. #define YYPOPSTACK   (gtdvsp--, gtdssp--)
  539. #endif
  540.  
  541.   int gtdstacksize = YYINITDEPTH;
  542.  
  543. #ifdef YYPURE
  544.   int gtdchar;
  545.   YYSTYPE gtdlval;
  546.   int gtdnerrs;
  547. #ifdef YYLSP_NEEDED
  548.   YYLTYPE gtdlloc;
  549. #endif
  550. #endif
  551.  
  552.   YYSTYPE gtdval;        /*  the variable used to return        */
  553.                 /*  semantic values from the action    */
  554.                 /*  routines                */
  555.  
  556.   int gtdlen;
  557.  
  558. #if YYDEBUG != 0
  559.   if (gtddebug)
  560.     fprintf(stderr, "Starting parse\n");
  561. #endif
  562.  
  563.   gtdstate = 0;
  564.   gtderrstatus = 0;
  565.   gtdnerrs = 0;
  566.   gtdchar = YYEMPTY;        /* Cause a token to be read.  */
  567.  
  568.   /* Initialize stack pointers.
  569.      Waste one element of value and location stack
  570.      so that they stay on the same level as the state stack.
  571.      The wasted elements are never initialized.  */
  572.  
  573.   gtdssp = gtdss - 1;
  574.   gtdvsp = gtdvs;
  575. #ifdef YYLSP_NEEDED
  576.   gtdlsp = gtdls;
  577. #endif
  578.  
  579. /* Push a new state, which is found in  gtdstate  .  */
  580. /* In all cases, when you get here, the value and location stacks
  581.    have just been pushed. so pushing a state here evens the stacks.  */
  582. gtdnewstate:
  583.  
  584.   *++gtdssp = gtdstate;
  585.  
  586.   if (gtdssp >= gtdss + gtdstacksize - 1)
  587.     {
  588.       /* Give user a chance to reallocate the stack */
  589.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  590.       YYSTYPE *gtdvs1 = gtdvs;
  591.       short *gtdss1 = gtdss;
  592. #ifdef YYLSP_NEEDED
  593.       YYLTYPE *gtdls1 = gtdls;
  594. #endif
  595.  
  596.       /* Get the current used size of the three stacks, in elements.  */
  597.       int size = gtdssp - gtdss + 1;
  598.  
  599. #ifdef gtdoverflow
  600.       /* Each stack pointer address is followed by the size of
  601.      the data in use in that stack, in bytes.  */
  602.       gtdoverflow("parser stack overflow",
  603.          >dss1, size * sizeof (*gtdssp),
  604.          >dvs1, size * sizeof (*gtdvsp),
  605. #ifdef YYLSP_NEEDED
  606.          >dls1, size * sizeof (*gtdlsp),
  607. #endif
  608.          >dstacksize);
  609.  
  610.       gtdss = gtdss1; gtdvs = gtdvs1;
  611. #ifdef YYLSP_NEEDED
  612.       gtdls = gtdls1;
  613. #endif
  614. #else /* no gtdoverflow */
  615.       /* Extend the stack our own way.  */
  616.       if (gtdstacksize >= YYMAXDEPTH)
  617.     {
  618.       gtderror("parser stack overflow");
  619.       return 2;
  620.     }
  621.       gtdstacksize *= 2;
  622.       if (gtdstacksize > YYMAXDEPTH)
  623.     gtdstacksize = YYMAXDEPTH;
  624.       gtdss = (short *) alloca (gtdstacksize * sizeof (*gtdssp));
  625.       __gtd_bcopy ((char *)gtdss1, (char *)gtdss, size * sizeof (*gtdssp));
  626.       gtdvs = (YYSTYPE *) alloca (gtdstacksize * sizeof (*gtdvsp));
  627.       __gtd_bcopy ((char *)gtdvs1, (char *)gtdvs, size * sizeof (*gtdvsp));
  628. #ifdef YYLSP_NEEDED
  629.       gtdls = (YYLTYPE *) alloca (gtdstacksize * sizeof (*gtdlsp));
  630.       __gtd_bcopy ((char *)gtdls1, (char *)gtdls, size * sizeof (*gtdlsp));
  631. #endif
  632. #endif /* no gtdoverflow */
  633.  
  634.       gtdssp = gtdss + size - 1;
  635.       gtdvsp = gtdvs + size - 1;
  636. #ifdef YYLSP_NEEDED
  637.       gtdlsp = gtdls + size - 1;
  638. #endif
  639.  
  640. #if YYDEBUG != 0
  641.       if (gtddebug)
  642.     fprintf(stderr, "Stack size increased to %d\n", gtdstacksize);
  643. #endif
  644.  
  645.       if (gtdssp >= gtdss + gtdstacksize - 1)
  646.     YYABORT;
  647.     }
  648.  
  649. #if YYDEBUG != 0
  650.   if (gtddebug)
  651.     fprintf(stderr, "Entering state %d\n", gtdstate);
  652. #endif
  653.  
  654.   goto gtdbackup;
  655.  gtdbackup:
  656.  
  657. /* Do appropriate processing given the current state.  */
  658. /* Read a lookahead token if we need one and don't already have one.  */
  659. /* gtdresume: */
  660.  
  661.   /* First try to decide what to do without reference to lookahead token.  */
  662.  
  663.   gtdn = gtdpact[gtdstate];
  664.   if (gtdn == YYFLAG)
  665.     goto gtddefault;
  666.  
  667.   /* Not known => get a lookahead token if don't already have one.  */
  668.  
  669.   /* gtdchar is either YYEMPTY or YYEOF
  670.      or a valid token in external form.  */
  671.  
  672.   if (gtdchar == YYEMPTY)
  673.     {
  674. #if YYDEBUG != 0
  675.       if (gtddebug)
  676.     fprintf(stderr, "Reading a token: ");
  677. #endif
  678.       gtdchar = YYLEX;
  679.     }
  680.  
  681.   /* Convert token to internal form (in gtdchar1) for indexing tables with */
  682.  
  683.   if (gtdchar <= 0)        /* This means end of input. */
  684.     {
  685.       gtdchar1 = 0;
  686.       gtdchar = YYEOF;        /* Don't call YYLEX any more */
  687.  
  688. #if YYDEBUG != 0
  689.       if (gtddebug)
  690.     fprintf(stderr, "Now at end of input.\n");
  691. #endif
  692.     }
  693.   else
  694.     {
  695.       gtdchar1 = YYTRANSLATE(gtdchar);
  696.  
  697. #if YYDEBUG != 0
  698.       if (gtddebug)
  699.     {
  700.       fprintf (stderr, "Next token is %d (%s", gtdchar, gtdtname[gtdchar1]);
  701.       /* Give the individual parser a way to print the precise meaning
  702.          of a token, for further debugging info.  */
  703. #ifdef YYPRINT
  704.       YYPRINT (stderr, gtdchar, gtdlval);
  705. #endif
  706.       fprintf (stderr, ")\n");
  707.     }
  708. #endif
  709.     }
  710.  
  711.   gtdn += gtdchar1;
  712.   if (gtdn < 0 || gtdn > YYLAST || gtdcheck[gtdn] != gtdchar1)
  713.     goto gtddefault;
  714.  
  715.   gtdn = gtdtable[gtdn];
  716.  
  717.   /* gtdn is what to do for this token type in this state.
  718.      Negative => reduce, -gtdn is rule number.
  719.      Positive => shift, gtdn is new state.
  720.        New state is final state => don't bother to shift,
  721.        just return success.
  722.      0, or most negative number => error.  */
  723.  
  724.   if (gtdn < 0)
  725.     {
  726.       if (gtdn == YYFLAG)
  727.     goto gtderrlab;
  728.       gtdn = -gtdn;
  729.       goto gtdreduce;
  730.     }
  731.   else if (gtdn == 0)
  732.     goto gtderrlab;
  733.  
  734.   if (gtdn == YYFINAL)
  735.     YYACCEPT;
  736.  
  737.   /* Shift the lookahead token.  */
  738.  
  739. #if YYDEBUG != 0
  740.   if (gtddebug)
  741.     fprintf(stderr, "Shifting token %d (%s), ", gtdchar, gtdtname[gtdchar1]);
  742. #endif
  743.  
  744.   /* Discard the token being shifted unless it is eof.  */
  745.   if (gtdchar != YYEOF)
  746.     gtdchar = YYEMPTY;
  747.  
  748.   *++gtdvsp = gtdlval;
  749. #ifdef YYLSP_NEEDED
  750.   *++gtdlsp = gtdlloc;
  751. #endif
  752.  
  753.   /* count tokens shifted since error; after three, turn off error status.  */
  754.   if (gtderrstatus) gtderrstatus--;
  755.  
  756.   gtdstate = gtdn;
  757.   goto gtdnewstate;
  758.  
  759. /* Do the default action for the current state.  */
  760. gtddefault:
  761.  
  762.   gtdn = gtddefact[gtdstate];
  763.   if (gtdn == 0)
  764.     goto gtderrlab;
  765.  
  766. /* Do a reduction.  gtdn is the number of a rule to reduce with.  */
  767. gtdreduce:
  768.   gtdlen = gtdr2[gtdn];
  769.   gtdval = gtdvsp[1-gtdlen]; /* implement default value of the action */
  770.  
  771. #if YYDEBUG != 0
  772.   if (gtddebug)
  773.     {
  774.       int i;
  775.  
  776.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  777.            gtdn, gtdrline[gtdn]);
  778.  
  779.       /* Print the symbols being reduced, and their result.  */
  780.       for (i = gtdprhs[gtdn]; gtdrhs[i] > 0; i++)
  781.     fprintf (stderr, "%s ", gtdtname[gtdrhs[i]]);
  782.       fprintf (stderr, " -> %s\n", gtdtname[gtdr1[gtdn]]);
  783.     }
  784. #endif
  785.  
  786.  
  787.   switch (gtdn) {
  788.  
  789. case 3:
  790. #line 181 "getdate.y"
  791. {
  792.         gtdHaveTime++;
  793.     ;
  794.     break;}
  795. case 4:
  796. #line 184 "getdate.y"
  797. {
  798.         gtdHaveZone++;
  799.     ;
  800.     break;}
  801. case 5:
  802. #line 187 "getdate.y"
  803. {
  804.         gtdHaveDate++;
  805.     ;
  806.     break;}
  807. case 6:
  808. #line 190 "getdate.y"
  809. {
  810.         gtdHaveDay++;
  811.     ;
  812.     break;}
  813. case 7:
  814. #line 193 "getdate.y"
  815. {
  816.         gtdHaveRel++;
  817.     ;
  818.     break;}
  819. case 9:
  820. #line 199 "getdate.y"
  821. {
  822.         gtdHour = gtdvsp[-1].Number;
  823.         gtdMinutes = 0;
  824.         gtdSeconds = 0;
  825.         gtdMeridian = gtdvsp[0].Meridian;
  826.     ;
  827.     break;}
  828. case 10:
  829. #line 205 "getdate.y"
  830. {
  831.         gtdHour = gtdvsp[-3].Number;
  832.         gtdMinutes = gtdvsp[-1].Number;
  833.         gtdSeconds = 0;
  834.         gtdMeridian = gtdvsp[0].Meridian;
  835.     ;
  836.     break;}
  837. case 11:
  838. #line 211 "getdate.y"
  839. {
  840.         gtdHour = gtdvsp[-3].Number;
  841.         gtdMinutes = gtdvsp[-1].Number;
  842.         gtdMeridian = MER24;
  843.         gtdDSTmode = DSToff;
  844.         gtdTimezone = - (gtdvsp[0].Number % 100 + (gtdvsp[0].Number / 100) * 60);
  845.     ;
  846.     break;}
  847. case 12:
  848. #line 218 "getdate.y"
  849. {
  850.         gtdHour = gtdvsp[-5].Number;
  851.         gtdMinutes = gtdvsp[-3].Number;
  852.         gtdSeconds = gtdvsp[-1].Number;
  853.         gtdMeridian = gtdvsp[0].Meridian;
  854.     ;
  855.     break;}
  856. case 13:
  857. #line 224 "getdate.y"
  858. {
  859.         gtdHour = gtdvsp[-5].Number;
  860.         gtdMinutes = gtdvsp[-3].Number;
  861.         gtdSeconds = gtdvsp[-1].Number;
  862.         gtdMeridian = MER24;
  863.         gtdDSTmode = DSToff;
  864.         gtdTimezone = - (gtdvsp[0].Number % 100 + (gtdvsp[0].Number / 100) * 60);
  865.     ;
  866.     break;}
  867. case 14:
  868. #line 234 "getdate.y"
  869. {
  870.         gtdTimezone = gtdvsp[0].Number;
  871.         gtdDSTmode = DSToff;
  872.     ;
  873.     break;}
  874. case 15:
  875. #line 238 "getdate.y"
  876. {
  877.         gtdTimezone = gtdvsp[0].Number;
  878.         gtdDSTmode = DSTon;
  879.     ;
  880.     break;}
  881. case 16:
  882. #line 243 "getdate.y"
  883. {
  884.         gtdTimezone = gtdvsp[-1].Number;
  885.         gtdDSTmode = DSTon;
  886.     ;
  887.     break;}
  888. case 17:
  889. #line 249 "getdate.y"
  890. {
  891.         gtdDayOrdinal = 1;
  892.         gtdDayNumber = gtdvsp[0].Number;
  893.     ;
  894.     break;}
  895. case 18:
  896. #line 253 "getdate.y"
  897. {
  898.         gtdDayOrdinal = 1;
  899.         gtdDayNumber = gtdvsp[-1].Number;
  900.     ;
  901.     break;}
  902. case 19:
  903. #line 257 "getdate.y"
  904. {
  905.         gtdDayOrdinal = gtdvsp[-1].Number;
  906.         gtdDayNumber = gtdvsp[0].Number;
  907.     ;
  908.     break;}
  909. case 20:
  910. #line 263 "getdate.y"
  911. {
  912.         gtdMonth = gtdvsp[-2].Number;
  913.         gtdDay = gtdvsp[0].Number;
  914.     ;
  915.     break;}
  916. case 21:
  917. #line 267 "getdate.y"
  918. {
  919.         gtdMonth = gtdvsp[-4].Number;
  920.         gtdDay = gtdvsp[-2].Number;
  921.         gtdYear = gtdvsp[0].Number;
  922.     ;
  923.     break;}
  924. case 22:
  925. #line 272 "getdate.y"
  926. {
  927.         /* ISO 8601 format.  gtdgtd-mm-dd.  */
  928.         gtdYear = gtdvsp[-2].Number;
  929.         gtdMonth = -gtdvsp[-1].Number;
  930.         gtdDay = -gtdvsp[0].Number;
  931.     ;
  932.     break;}
  933. case 23:
  934. #line 278 "getdate.y"
  935. {
  936.         gtdMonth = gtdvsp[-1].Number;
  937.         gtdDay = gtdvsp[0].Number;
  938.     ;
  939.     break;}
  940. case 24:
  941. #line 282 "getdate.y"
  942. {
  943.         gtdMonth = gtdvsp[-3].Number;
  944.         gtdDay = gtdvsp[-2].Number;
  945.         gtdYear = gtdvsp[0].Number;
  946.     ;
  947.     break;}
  948. case 25:
  949. #line 287 "getdate.y"
  950. {
  951.         gtdMonth = gtdvsp[0].Number;
  952.         gtdDay = gtdvsp[-1].Number;
  953.     ;
  954.     break;}
  955. case 26:
  956. #line 291 "getdate.y"
  957. {
  958.         gtdMonth = gtdvsp[-1].Number;
  959.         gtdDay = gtdvsp[-2].Number;
  960.         gtdYear = gtdvsp[0].Number;
  961.     ;
  962.     break;}
  963. case 27:
  964. #line 298 "getdate.y"
  965. {
  966.         gtdRelSeconds = -gtdRelSeconds;
  967.         gtdRelMonth = -gtdRelMonth;
  968.     ;
  969.     break;}
  970. case 29:
  971. #line 305 "getdate.y"
  972. {
  973.         gtdRelSeconds += gtdvsp[-1].Number * gtdvsp[0].Number * 60L;
  974.     ;
  975.     break;}
  976. case 30:
  977. #line 308 "getdate.y"
  978. {
  979.         gtdRelSeconds += gtdvsp[-1].Number * gtdvsp[0].Number * 60L;
  980.     ;
  981.     break;}
  982. case 31:
  983. #line 311 "getdate.y"
  984. {
  985.         gtdRelSeconds += gtdvsp[0].Number * 60L;
  986.     ;
  987.     break;}
  988. case 32:
  989. #line 314 "getdate.y"
  990. {
  991.         gtdRelSeconds += gtdvsp[-1].Number;
  992.     ;
  993.     break;}
  994. case 33:
  995. #line 317 "getdate.y"
  996. {
  997.         gtdRelSeconds += gtdvsp[-1].Number;
  998.     ;
  999.     break;}
  1000. case 34:
  1001. #line 320 "getdate.y"
  1002. {
  1003.         gtdRelSeconds++;
  1004.     ;
  1005.     break;}
  1006. case 35:
  1007. #line 323 "getdate.y"
  1008. {
  1009.         gtdRelMonth += gtdvsp[-1].Number * gtdvsp[0].Number;
  1010.     ;
  1011.     break;}
  1012. case 36:
  1013. #line 326 "getdate.y"
  1014. {
  1015.         gtdRelMonth += gtdvsp[-1].Number * gtdvsp[0].Number;
  1016.     ;
  1017.     break;}
  1018. case 37:
  1019. #line 329 "getdate.y"
  1020. {
  1021.         gtdRelMonth += gtdvsp[0].Number;
  1022.     ;
  1023.     break;}
  1024. case 38:
  1025. #line 334 "getdate.y"
  1026. {
  1027.         if (gtdHaveTime && gtdHaveDate && !gtdHaveRel)
  1028.         gtdYear = gtdvsp[0].Number;
  1029.         else {
  1030.         if(gtdvsp[0].Number>10000) {
  1031.             time_t date_part;
  1032.  
  1033.             date_part= gtdvsp[0].Number/10000;
  1034.             gtdHaveDate++;
  1035.             gtdDay= (date_part)%100;
  1036.             gtdMonth= (date_part/100)%100;
  1037.             gtdYear = date_part/10000;
  1038.         } 
  1039.             gtdHaveTime++;
  1040.         if (gtdvsp[0].Number < 100) {
  1041.             gtdHour = gtdvsp[0].Number;
  1042.             gtdMinutes = 0;
  1043.         }
  1044.         else {
  1045.             gtdHour = gtdvsp[0].Number / 100;
  1046.             gtdMinutes = gtdvsp[0].Number % 100;
  1047.         }
  1048.         gtdSeconds = 0;
  1049.         gtdMeridian = MER24;
  1050.         }
  1051.     ;
  1052.     break;}
  1053. case 39:
  1054. #line 362 "getdate.y"
  1055. {
  1056.         gtdval.Meridian = MER24;
  1057.     ;
  1058.     break;}
  1059. case 40:
  1060. #line 365 "getdate.y"
  1061. {
  1062.         gtdval.Meridian = gtdvsp[0].Meridian;
  1063.     ;
  1064.     break;}
  1065. }
  1066.    /* the action file gets copied in in place of this dollarsign */
  1067. #line 442 "/afs/andrew/usr11/lord//lib/bison.simple"
  1068.  
  1069.   gtdvsp -= gtdlen;
  1070.   gtdssp -= gtdlen;
  1071. #ifdef YYLSP_NEEDED
  1072.   gtdlsp -= gtdlen;
  1073. #endif
  1074.  
  1075. #if YYDEBUG != 0
  1076.   if (gtddebug)
  1077.     {
  1078.       short *ssp1 = gtdss - 1;
  1079.       fprintf (stderr, "state stack now");
  1080.       while (ssp1 != gtdssp)
  1081.     fprintf (stderr, " %d", *++ssp1);
  1082.       fprintf (stderr, "\n");
  1083.     }
  1084. #endif
  1085.  
  1086.   *++gtdvsp = gtdval;
  1087.  
  1088. #ifdef YYLSP_NEEDED
  1089.   gtdlsp++;
  1090.   if (gtdlen == 0)
  1091.     {
  1092.       gtdlsp->first_line = gtdlloc.first_line;
  1093.       gtdlsp->first_column = gtdlloc.first_column;
  1094.       gtdlsp->last_line = (gtdlsp-1)->last_line;
  1095.       gtdlsp->last_column = (gtdlsp-1)->last_column;
  1096.       gtdlsp->text = 0;
  1097.     }
  1098.   else
  1099.     {
  1100.       gtdlsp->last_line = (gtdlsp+gtdlen-1)->last_line;
  1101.       gtdlsp->last_column = (gtdlsp+gtdlen-1)->last_column;
  1102.     }
  1103. #endif
  1104.  
  1105.   /* Now "shift" the result of the reduction.
  1106.      Determine what state that goes to,
  1107.      based on the state we popped back to
  1108.      and the rule number reduced by.  */
  1109.  
  1110.   gtdn = gtdr1[gtdn];
  1111.  
  1112.   gtdstate = gtdpgoto[gtdn - YYNTBASE] + *gtdssp;
  1113.   if (gtdstate >= 0 && gtdstate <= YYLAST && gtdcheck[gtdstate] == *gtdssp)
  1114.     gtdstate = gtdtable[gtdstate];
  1115.   else
  1116.     gtdstate = gtddefgoto[gtdn - YYNTBASE];
  1117.  
  1118.   goto gtdnewstate;
  1119.  
  1120. gtderrlab:   /* here on detecting error */
  1121.  
  1122.   if (! gtderrstatus)
  1123.     /* If not already recovering from an error, report this error.  */
  1124.     {
  1125.       ++gtdnerrs;
  1126.  
  1127. #ifdef YYERROR_VERBOSE
  1128.       gtdn = gtdpact[gtdstate];
  1129.  
  1130.       if (gtdn > YYFLAG && gtdn < YYLAST)
  1131.     {
  1132.       int size = 0;
  1133.       char *msg;
  1134.       int x, count;
  1135.  
  1136.       count = 0;
  1137.       for (x = 0; x < (sizeof(gtdtname) / sizeof(char *)); x++)
  1138.         if (gtdcheck[x + gtdn] == x)
  1139.           size += strlen(gtdtname[x]) + 15, count++;
  1140.       msg = (char *) malloc(size + 15);
  1141.       if (msg != 0)
  1142.         {
  1143.           strcpy(msg, "parse error");
  1144.  
  1145.           if (count < 5)
  1146.         {
  1147.           count = 0;
  1148.           for (x = 0; x < (sizeof(gtdtname) / sizeof(char *)); x++)
  1149.             if (gtdcheck[x + gtdn] == x)
  1150.               {
  1151.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1152.             strcat(msg, gtdtname[x]);
  1153.             strcat(msg, "'");
  1154.             count++;
  1155.               }
  1156.         }
  1157.           gtderror(msg);
  1158.           free(msg);
  1159.         }
  1160.       else
  1161.         gtderror ("parse error; also virtual memory exceeded");
  1162.     }
  1163.       else
  1164. #endif /* YYERROR_VERBOSE */
  1165.     gtderror("parse error");
  1166.     }
  1167.  
  1168.   goto gtderrlab1;
  1169. gtderrlab1:   /* here on error raised explicitly by an action */
  1170.  
  1171.   if (gtderrstatus == 3)
  1172.     {
  1173.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1174.  
  1175.       /* return failure if at end of input */
  1176.       if (gtdchar == YYEOF)
  1177.     YYABORT;
  1178.  
  1179. #if YYDEBUG != 0
  1180.       if (gtddebug)
  1181.     fprintf(stderr, "Discarding token %d (%s).\n", gtdchar, gtdtname[gtdchar1]);
  1182. #endif
  1183.  
  1184.       gtdchar = YYEMPTY;
  1185.     }
  1186.  
  1187.   /* Else will try to reuse lookahead token
  1188.      after shifting the error token.  */
  1189.  
  1190.   gtderrstatus = 3;        /* Each real token shifted decrements this */
  1191.  
  1192.   goto gtderrhandle;
  1193.  
  1194. gtderrdefault:  /* current state does not do anything special for the error token. */
  1195.  
  1196. #if 0
  1197.   /* This is wrong; only states that explicitly want error tokens
  1198.      should shift them.  */
  1199.   gtdn = gtddefact[gtdstate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1200.   if (gtdn) goto gtddefault;
  1201. #endif
  1202.  
  1203. gtderrpop:   /* pop the current state because it cannot handle the error token */
  1204.  
  1205.   if (gtdssp == gtdss) YYABORT;
  1206.   gtdvsp--;
  1207.   gtdstate = *--gtdssp;
  1208. #ifdef YYLSP_NEEDED
  1209.   gtdlsp--;
  1210. #endif
  1211.  
  1212. #if YYDEBUG != 0
  1213.   if (gtddebug)
  1214.     {
  1215.       short *ssp1 = gtdss - 1;
  1216.       fprintf (stderr, "Error: state stack now");
  1217.       while (ssp1 != gtdssp)
  1218.     fprintf (stderr, " %d", *++ssp1);
  1219.       fprintf (stderr, "\n");
  1220.     }
  1221. #endif
  1222.  
  1223. gtderrhandle:
  1224.  
  1225.   gtdn = gtdpact[gtdstate];
  1226.   if (gtdn == YYFLAG)
  1227.     goto gtderrdefault;
  1228.  
  1229.   gtdn += YYTERROR;
  1230.   if (gtdn < 0 || gtdn > YYLAST || gtdcheck[gtdn] != YYTERROR)
  1231.     goto gtderrdefault;
  1232.  
  1233.   gtdn = gtdtable[gtdn];
  1234.   if (gtdn < 0)
  1235.     {
  1236.       if (gtdn == YYFLAG)
  1237.     goto gtderrpop;
  1238.       gtdn = -gtdn;
  1239.       goto gtdreduce;
  1240.     }
  1241.   else if (gtdn == 0)
  1242.     goto gtderrpop;
  1243.  
  1244.   if (gtdn == YYFINAL)
  1245.     YYACCEPT;
  1246.  
  1247. #if YYDEBUG != 0
  1248.   if (gtddebug)
  1249.     fprintf(stderr, "Shifting error token, ");
  1250. #endif
  1251.  
  1252.   *++gtdvsp = gtdlval;
  1253. #ifdef YYLSP_NEEDED
  1254.   *++gtdlsp = gtdlloc;
  1255. #endif
  1256.  
  1257.   gtdstate = gtdn;
  1258.   goto gtdnewstate;
  1259. }
  1260. #line 370 "getdate.y"
  1261.  
  1262.  
  1263. /* Month and day table. */
  1264. static TABLE const MonthDayTable[] = {
  1265.     { "january",    tMONTH,  1 },
  1266.     { "february",    tMONTH,  2 },
  1267.     { "march",        tMONTH,  3 },
  1268.     { "april",        tMONTH,  4 },
  1269.     { "may",        tMONTH,  5 },
  1270.     { "june",        tMONTH,  6 },
  1271.     { "july",        tMONTH,  7 },
  1272.     { "august",        tMONTH,  8 },
  1273.     { "september",    tMONTH,  9 },
  1274.     { "sept",        tMONTH,  9 },
  1275.     { "october",    tMONTH, 10 },
  1276.     { "november",    tMONTH, 11 },
  1277.     { "december",    tMONTH, 12 },
  1278.     { "sunday",        tDAY, 0 },
  1279.     { "monday",        tDAY, 1 },
  1280.     { "tuesday",    tDAY, 2 },
  1281.     { "tues",        tDAY, 2 },
  1282.     { "wednesday",    tDAY, 3 },
  1283.     { "wednes",        tDAY, 3 },
  1284.     { "thursday",    tDAY, 4 },
  1285.     { "thur",        tDAY, 4 },
  1286.     { "thurs",        tDAY, 4 },
  1287.     { "friday",        tDAY, 5 },
  1288.     { "saturday",    tDAY, 6 },
  1289.     { NULL }
  1290. };
  1291.  
  1292. /* Time units table. */
  1293. static TABLE const UnitsTable[] = {
  1294.     { "year",        tMONTH_UNIT,    12 },
  1295.     { "month",        tMONTH_UNIT,    1 },
  1296.     { "fortnight",    tMINUTE_UNIT,    14 * 24 * 60 },
  1297.     { "week",        tMINUTE_UNIT,    7 * 24 * 60 },
  1298.     { "day",        tMINUTE_UNIT,    1 * 24 * 60 },
  1299.     { "hour",        tMINUTE_UNIT,    60 },
  1300.     { "minute",        tMINUTE_UNIT,    1 },
  1301.     { "min",        tMINUTE_UNIT,    1 },
  1302.     { "second",        tSEC_UNIT,    1 },
  1303.     { "sec",        tSEC_UNIT,    1 },
  1304.     { NULL }
  1305. };
  1306.  
  1307. /* Assorted relative-time words. */
  1308. static TABLE const OtherTable[] = {
  1309.     { "tomorrow",    tMINUTE_UNIT,    1 * 24 * 60 },
  1310.     { "yesterday",    tMINUTE_UNIT,    -1 * 24 * 60 },
  1311.     { "today",        tMINUTE_UNIT,    0 },
  1312.     { "now",        tMINUTE_UNIT,    0 },
  1313.     { "last",        tUNUMBER,    -1 },
  1314.     { "this",        tMINUTE_UNIT,    0 },
  1315.     { "next",        tUNUMBER,    2 },
  1316.     { "first",        tUNUMBER,    1 },
  1317. /*  { "second",        tUNUMBER,    2 }, */
  1318.     { "third",        tUNUMBER,    3 },
  1319.     { "fourth",        tUNUMBER,    4 },
  1320.     { "fifth",        tUNUMBER,    5 },
  1321.     { "sixth",        tUNUMBER,    6 },
  1322.     { "seventh",    tUNUMBER,    7 },
  1323.     { "eighth",        tUNUMBER,    8 },
  1324.     { "ninth",        tUNUMBER,    9 },
  1325.     { "tenth",        tUNUMBER,    10 },
  1326.     { "eleventh",    tUNUMBER,    11 },
  1327.     { "twelfth",    tUNUMBER,    12 },
  1328.     { "ago",        tAGO,    1 },
  1329.     { NULL }
  1330. };
  1331.  
  1332. /* The timezone table. */
  1333. /* Some of these are commented out because a time_t can't store a float. */
  1334. static TABLE const TimezoneTable[] = {
  1335.     { "gmt",    tZONE,     HOUR( 0) },    /* Greenwich Mean */
  1336.     { "ut",    tZONE,     HOUR( 0) },    /* Universal (Coordinated) */
  1337.     { "utc",    tZONE,     HOUR( 0) },
  1338.     { "wet",    tZONE,     HOUR( 0) },    /* Western European */
  1339.     { "bst",    tDAYZONE,  HOUR( 0) },    /* British Summer */
  1340.     { "wat",    tZONE,     HOUR( 1) },    /* West Africa */
  1341.     { "at",    tZONE,     HOUR( 2) },    /* Azores */
  1342. #if    0
  1343.     /* For completeness.  BST is also British Summer, and GST is
  1344.      * also Guam Standard. */
  1345.     { "bst",    tZONE,     HOUR( 3) },    /* Brazil Standard */
  1346.     { "gst",    tZONE,     HOUR( 3) },    /* Greenland Standard */
  1347. #endif
  1348. #if 0
  1349.     { "nft",    tZONE,     HOUR(3.5) },    /* Newfoundland */
  1350.     { "nst",    tZONE,     HOUR(3.5) },    /* Newfoundland Standard */
  1351.     { "ndt",    tDAYZONE,  HOUR(3.5) },    /* Newfoundland Daylight */
  1352. #endif
  1353.     { "ast",    tZONE,     HOUR( 4) },    /* Atlantic Standard */
  1354.     { "adt",    tDAYZONE,  HOUR( 4) },    /* Atlantic Daylight */
  1355.     { "est",    tZONE,     HOUR( 5) },    /* Eastern Standard */
  1356.     { "edt",    tDAYZONE,  HOUR( 5) },    /* Eastern Daylight */
  1357.     { "cst",    tZONE,     HOUR( 6) },    /* Central Standard */
  1358.     { "cdt",    tDAYZONE,  HOUR( 6) },    /* Central Daylight */
  1359.     { "mst",    tZONE,     HOUR( 7) },    /* Mountain Standard */
  1360.     { "mdt",    tDAYZONE,  HOUR( 7) },    /* Mountain Daylight */
  1361.     { "pst",    tZONE,     HOUR( 8) },    /* Pacific Standard */
  1362.     { "pdt",    tDAYZONE,  HOUR( 8) },    /* Pacific Daylight */
  1363.     { "yst",    tZONE,     HOUR( 9) },    /* Yukon Standard */
  1364.     { "ydt",    tDAYZONE,  HOUR( 9) },    /* Yukon Daylight */
  1365.     { "hst",    tZONE,     HOUR(10) },    /* Hawaii Standard */
  1366.     { "hdt",    tDAYZONE,  HOUR(10) },    /* Hawaii Daylight */
  1367.     { "cat",    tZONE,     HOUR(10) },    /* Central Alaska */
  1368.     { "ahst",    tZONE,     HOUR(10) },    /* Alaska-Hawaii Standard */
  1369.     { "nt",    tZONE,     HOUR(11) },    /* Nome */
  1370.     { "idlw",    tZONE,     HOUR(12) },    /* International Date Line West */
  1371.     { "cet",    tZONE,     -HOUR(1) },    /* Central European */
  1372.     { "met",    tZONE,     -HOUR(1) },    /* Middle European */
  1373.     { "mewt",    tZONE,     -HOUR(1) },    /* Middle European Winter */
  1374.     { "mest",    tDAYZONE,  -HOUR(1) },    /* Middle European Summer */
  1375.     { "swt",    tZONE,     -HOUR(1) },    /* Swedish Winter */
  1376.     { "sst",    tDAYZONE,  -HOUR(1) },    /* Swedish Summer */
  1377.     { "fwt",    tZONE,     -HOUR(1) },    /* French Winter */
  1378.     { "fst",    tDAYZONE,  -HOUR(1) },    /* French Summer */
  1379.     { "eet",    tZONE,     -HOUR(2) },    /* Eastern Europe, USSR Zone 1 */
  1380.     { "bt",    tZONE,     -HOUR(3) },    /* Baghdad, USSR Zone 2 */
  1381. #if 0
  1382.     { "it",    tZONE,     -HOUR(3.5) },/* Iran */
  1383. #endif
  1384.     { "zp4",    tZONE,     -HOUR(4) },    /* USSR Zone 3 */
  1385.     { "zp5",    tZONE,     -HOUR(5) },    /* USSR Zone 4 */
  1386. #if 0
  1387.     { "ist",    tZONE,     -HOUR(5.5) },/* Indian Standard */
  1388. #endif
  1389.     { "zp6",    tZONE,     -HOUR(6) },    /* USSR Zone 5 */
  1390. #if    0
  1391.     /* For completeness.  NST is also Newfoundland Stanard, and SST is
  1392.      * also Swedish Summer. */
  1393.     { "nst",    tZONE,     -HOUR(6.5) },/* North Sumatra */
  1394.     { "sst",    tZONE,     -HOUR(7) },    /* South Sumatra, USSR Zone 6 */
  1395. #endif    /* 0 */
  1396.     { "wast",    tZONE,     -HOUR(7) },    /* West Australian Standard */
  1397.     { "wadt",    tDAYZONE,  -HOUR(7) },    /* West Australian Daylight */
  1398. #if 0
  1399.     { "jt",    tZONE,     -HOUR(7.5) },/* Java (3pm in Cronusland!) */
  1400. #endif
  1401.     { "cct",    tZONE,     -HOUR(8) },    /* China Coast, USSR Zone 7 */
  1402.     { "jst",    tZONE,     -HOUR(9) },    /* Japan Standard, USSR Zone 8 */
  1403. #if 0
  1404.     { "cast",    tZONE,     -HOUR(9.5) },/* Central Australian Standard */
  1405.     { "cadt",    tDAYZONE,  -HOUR(9.5) },/* Central Australian Daylight */
  1406. #endif
  1407.     { "east",    tZONE,     -HOUR(10) },    /* Eastern Australian Standard */
  1408.     { "eadt",    tDAYZONE,  -HOUR(10) },    /* Eastern Australian Daylight */
  1409.     { "gst",    tZONE,     -HOUR(10) },    /* Guam Standard, USSR Zone 9 */
  1410.     { "nzt",    tZONE,     -HOUR(12) },    /* New Zealand */
  1411.     { "nzst",    tZONE,     -HOUR(12) },    /* New Zealand Standard */
  1412.     { "nzdt",    tDAYZONE,  -HOUR(12) },    /* New Zealand Daylight */
  1413.     { "idle",    tZONE,     -HOUR(12) },    /* International Date Line East */
  1414.     {  NULL  }
  1415. };
  1416.  
  1417. /* Military timezone table. */
  1418. static TABLE const MilitaryTable[] = {
  1419.     { "a",    tZONE,    HOUR(  1) },
  1420.     { "b",    tZONE,    HOUR(  2) },
  1421.     { "c",    tZONE,    HOUR(  3) },
  1422.     { "d",    tZONE,    HOUR(  4) },
  1423.     { "e",    tZONE,    HOUR(  5) },
  1424.     { "f",    tZONE,    HOUR(  6) },
  1425.     { "g",    tZONE,    HOUR(  7) },
  1426.     { "h",    tZONE,    HOUR(  8) },
  1427.     { "i",    tZONE,    HOUR(  9) },
  1428.     { "k",    tZONE,    HOUR( 10) },
  1429.     { "l",    tZONE,    HOUR( 11) },
  1430.     { "m",    tZONE,    HOUR( 12) },
  1431.     { "n",    tZONE,    HOUR(- 1) },
  1432.     { "o",    tZONE,    HOUR(- 2) },
  1433.     { "p",    tZONE,    HOUR(- 3) },
  1434.     { "q",    tZONE,    HOUR(- 4) },
  1435.     { "r",    tZONE,    HOUR(- 5) },
  1436.     { "s",    tZONE,    HOUR(- 6) },
  1437.     { "t",    tZONE,    HOUR(- 7) },
  1438.     { "u",    tZONE,    HOUR(- 8) },
  1439.     { "v",    tZONE,    HOUR(- 9) },
  1440.     { "w",    tZONE,    HOUR(-10) },
  1441.     { "x",    tZONE,    HOUR(-11) },
  1442.     { "y",    tZONE,    HOUR(-12) },
  1443.     { "z",    tZONE,    HOUR(  0) },
  1444.     { NULL }
  1445. };
  1446.  
  1447.  
  1448.  
  1449.  
  1450. /* ARGSUSED */
  1451. static int
  1452. gtderror(s)
  1453.     char    *s;
  1454. {
  1455.   return 0;
  1456. }
  1457.  
  1458.  
  1459. static time_t
  1460. ToSeconds(Hours, Minutes, Seconds, Meridian)
  1461.     time_t    Hours;
  1462.     time_t    Minutes;
  1463.     time_t    Seconds;
  1464.     MERIDIAN    Meridian;
  1465. {
  1466.     if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
  1467.     return -1;
  1468.     switch (Meridian) {
  1469.     case MER24:
  1470.     if (Hours < 0 || Hours > 23)
  1471.         return -1;
  1472.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1473.     case MERam:
  1474.     if (Hours < 1 || Hours > 12)
  1475.         return -1;
  1476.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1477.     case MERpm:
  1478.     if (Hours < 1 || Hours > 12)
  1479.         return -1;
  1480.     return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
  1481.     }
  1482.     /* NOTREACHED */
  1483. }
  1484.  
  1485.  
  1486. static time_t
  1487. Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
  1488.     time_t    Month;
  1489.     time_t    Day;
  1490.     time_t    Year;
  1491.     time_t    Hours;
  1492.     time_t    Minutes;
  1493.     time_t    Seconds;
  1494.     MERIDIAN    Meridian;
  1495.     DSTMODE    DSTmode;
  1496. {
  1497.     static int DaysInMonth[12] = {
  1498.     31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  1499.     };
  1500.     time_t    tod;
  1501.     time_t    Julian;
  1502.     int        i;
  1503.  
  1504.     if (Year < 0)
  1505.     Year = -Year;
  1506.     if (Year < 100)
  1507.     Year += 1900;
  1508.     DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
  1509.             ? 29 : 28;
  1510.     if (Year < EPOCH || Year > 1999
  1511.      || Month < 1 || Month > 12
  1512.      /* Lint fluff:  "conversion from long may lose accuracy" */
  1513.      || Day < 1 || Day > DaysInMonth[(int)--Month])
  1514.     return -1;
  1515.  
  1516.     for (Julian = Day - 1, i = 0; i < Month; i++)
  1517.     Julian += DaysInMonth[i];
  1518.     for (i = EPOCH; i < Year; i++)
  1519.     Julian += 365 + (i % 4 == 0);
  1520.     Julian *= SECSPERDAY;
  1521.     Julian += gtdTimezone * 60L;
  1522.     if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
  1523.     return -1;
  1524.     Julian += tod;
  1525.     if (DSTmode == DSTon
  1526.      || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
  1527.     Julian -= 60 * 60;
  1528.     return Julian;
  1529. }
  1530.  
  1531.  
  1532. static time_t
  1533. DSTcorrect(Start, Future)
  1534.     time_t    Start;
  1535.     time_t    Future;
  1536. {
  1537.     time_t    StartDay;
  1538.     time_t    FutureDay;
  1539.  
  1540.     StartDay = (localtime(&Start)->tm_hour + 1) % 24;
  1541.     FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
  1542.     return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
  1543. }
  1544.  
  1545.  
  1546. static time_t
  1547. RelativeDate(Start, DayOrdinal, DayNumber)
  1548.     time_t    Start;
  1549.     time_t    DayOrdinal;
  1550.     time_t    DayNumber;
  1551. {
  1552.     struct tm    *tm;
  1553.     time_t    now;
  1554.  
  1555.     now = Start;
  1556.     tm = localtime(&now);
  1557.     now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
  1558.     now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
  1559.     return DSTcorrect(Start, now);
  1560. }
  1561.  
  1562.  
  1563. static time_t
  1564. RelativeMonth(Start, RelMonth)
  1565.     time_t    Start;
  1566.     time_t    RelMonth;
  1567. {
  1568.     struct tm    *tm;
  1569.     time_t    Month;
  1570.     time_t    Year;
  1571.  
  1572.     if (RelMonth == 0)
  1573.     return 0;
  1574.     tm = localtime(&Start);
  1575.     Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
  1576.     Year = Month / 12;
  1577.     Month = Month % 12 + 1;
  1578.     return DSTcorrect(Start,
  1579.         Convert(Month, (time_t)tm->tm_mday, Year,
  1580.         (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
  1581.         MER24, DSTmaybe));
  1582. }
  1583.  
  1584.  
  1585. static int
  1586. LookupWord(buff)
  1587.     char        *buff;
  1588. {
  1589.     register char    *p;
  1590.     register char    *q;
  1591.     register const TABLE    *tp;
  1592.     int            i;
  1593.     int            abbrev;
  1594.  
  1595.     /* Make it lowercase. */
  1596.     for (p = buff; *p; p++)
  1597.     if (isupper(*p))
  1598.         *p = tolower(*p);
  1599.  
  1600.     if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
  1601.     gtdlval.Meridian = MERam;
  1602.     return tMERIDIAN;
  1603.     }
  1604.     if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
  1605.     gtdlval.Meridian = MERpm;
  1606.     return tMERIDIAN;
  1607.     }
  1608.  
  1609.     /* See if we have an abbreviation for a month. */
  1610.     if (strlen(buff) == 3)
  1611.     abbrev = 1;
  1612.     else if (strlen(buff) == 4 && buff[3] == '.') {
  1613.     abbrev = 1;
  1614.     buff[3] = '\0';
  1615.     }
  1616.     else
  1617.     abbrev = 0;
  1618.  
  1619.     for (tp = MonthDayTable; tp->name; tp++) {
  1620.     if (abbrev) {
  1621.         if (strncmp(buff, tp->name, 3) == 0) {
  1622.         gtdlval.Number = tp->value;
  1623.         return tp->type;
  1624.         }
  1625.     }
  1626.     else if (strcmp(buff, tp->name) == 0) {
  1627.         gtdlval.Number = tp->value;
  1628.         return tp->type;
  1629.     }
  1630.     }
  1631.  
  1632.     for (tp = TimezoneTable; tp->name; tp++)
  1633.     if (strcmp(buff, tp->name) == 0) {
  1634.         gtdlval.Number = tp->value;
  1635.         return tp->type;
  1636.     }
  1637.  
  1638.     if (strcmp(buff, "dst") == 0) 
  1639.     return tDST;
  1640.  
  1641.     for (tp = UnitsTable; tp->name; tp++)
  1642.     if (strcmp(buff, tp->name) == 0) {
  1643.         gtdlval.Number = tp->value;
  1644.         return tp->type;
  1645.     }
  1646.  
  1647.     /* Strip off any plural and try the units table again. */
  1648.     i = strlen(buff) - 1;
  1649.     if (buff[i] == 's') {
  1650.     buff[i] = '\0';
  1651.     for (tp = UnitsTable; tp->name; tp++)
  1652.         if (strcmp(buff, tp->name) == 0) {
  1653.         gtdlval.Number = tp->value;
  1654.         return tp->type;
  1655.         }
  1656.     buff[i] = 's';        /* Put back for "this" in OtherTable. */
  1657.     }
  1658.  
  1659.     for (tp = OtherTable; tp->name; tp++)
  1660.     if (strcmp(buff, tp->name) == 0) {
  1661.         gtdlval.Number = tp->value;
  1662.         return tp->type;
  1663.     }
  1664.  
  1665.     /* Military timezones. */
  1666.     if (buff[1] == '\0' && isalpha(*buff)) {
  1667.     for (tp = MilitaryTable; tp->name; tp++)
  1668.         if (strcmp(buff, tp->name) == 0) {
  1669.         gtdlval.Number = tp->value;
  1670.         return tp->type;
  1671.         }
  1672.     }
  1673.  
  1674.     /* Drop out any periods and try the timezone table again. */
  1675.     for (i = 0, p = q = buff; *q; q++)
  1676.     if (*q != '.')
  1677.         *p++ = *q;
  1678.     else
  1679.         i++;
  1680.     *p = '\0';
  1681.     if (i)
  1682.     for (tp = TimezoneTable; tp->name; tp++)
  1683.         if (strcmp(buff, tp->name) == 0) {
  1684.         gtdlval.Number = tp->value;
  1685.         return tp->type;
  1686.         }
  1687.  
  1688.     return tID;
  1689. }
  1690.  
  1691.  
  1692. static int
  1693. gtdlex()
  1694. {
  1695.     register char    c;
  1696.     register char    *p;
  1697.     char        buff[20];
  1698.     int            Count;
  1699.     int            sign;
  1700.  
  1701.     for ( ; ; ) {
  1702.     while (isspace(*gtdInput))
  1703.         gtdInput++;
  1704.  
  1705.     if (isdigit(c = *gtdInput) || c == '-' || c == '+') {
  1706.         if (c == '-' || c == '+') {
  1707.         sign = c == '-' ? -1 : 1;
  1708.         if (!isdigit(*++gtdInput))
  1709.             /* skip the '-' sign */
  1710.             continue;
  1711.         }
  1712.         else
  1713.         sign = 0;
  1714.         for (gtdlval.Number = 0; isdigit(c = *gtdInput++); )
  1715.         gtdlval.Number = 10 * gtdlval.Number + c - '0';
  1716.         gtdInput--;
  1717.         if (sign < 0)
  1718.         gtdlval.Number = -gtdlval.Number;
  1719.         return sign ? tSNUMBER : tUNUMBER;
  1720.     }
  1721.     if (isalpha(c)) {
  1722.         for (p = buff; isalpha(c = *gtdInput++) || c == '.'; )
  1723.         if (p < &buff[sizeof buff - 1])
  1724.             *p++ = c;
  1725.         *p = '\0';
  1726.         gtdInput--;
  1727.         return LookupWord(buff);
  1728.     }
  1729.     if (c != '(')
  1730.         return *gtdInput++;
  1731.     Count = 0;
  1732.     do {
  1733.         c = *gtdInput++;
  1734.         if (c == '\0')
  1735.         return c;
  1736.         if (c == '(')
  1737.         Count++;
  1738.         else if (c == ')')
  1739.         Count--;
  1740.     } while (Count > 0);
  1741.     }
  1742. }
  1743.  
  1744.  
  1745. time_t
  1746. get_date(p, now)
  1747.     char        *p;
  1748.     struct timeb    *now;
  1749. {
  1750.     struct tm        *tm;
  1751.     struct timeb    ftz;
  1752.     time_t        Start;
  1753.     time_t        tod;
  1754.  
  1755.     gtdInput = p;
  1756.     if (now == NULL) {
  1757.         now = &ftz;
  1758. #if    !defined(HAVE_FTIME)
  1759.     (void)time(&ftz.time);
  1760.     /* Set the timezone global. */
  1761.     tzset();
  1762.     {
  1763. #if sgi
  1764.         ftz.timezone = (int) _timezone / 60;
  1765. #else /* not sgi */
  1766. #ifdef __386BSD__
  1767.         ftz.timezone = 0;
  1768. #else /* neither sgi nor 386BSD */
  1769. #if defined (USG)
  1770.         extern time_t timezone;
  1771.  
  1772.         ftz.timezone = (int) timezone / 60;
  1773. #else /* neither sgi nor 386BSD nor USG */
  1774.         struct timeval tv;
  1775.         struct timezone tz;
  1776.         gettimeofday (&tv, &tz);
  1777.         ftz.timezone = (int) tz.tz_minuteswest;
  1778. #endif /* neither sgi nor 386BSD nor USG */
  1779. #endif /* neither sgi nor 386BSD */
  1780. #endif /* not sgi */
  1781.     }
  1782. #else /* HAVE_FTIME */
  1783.     (void)ftime(&ftz);
  1784. #endif /* HAVE_FTIME */
  1785.     }
  1786.  
  1787.     tm = localtime(&now->time);
  1788.     gtdYear = tm->tm_year;
  1789.     gtdMonth = tm->tm_mon + 1;
  1790.     gtdDay = tm->tm_mday;
  1791.     gtdTimezone = now->timezone;
  1792.     gtdDSTmode = DSTmaybe;
  1793.     gtdHour = 0;
  1794.     gtdMinutes = 0;
  1795.     gtdSeconds = 0;
  1796.     gtdMeridian = MER24;
  1797.     gtdRelSeconds = 0;
  1798.     gtdRelMonth = 0;
  1799.     gtdHaveDate = 0;
  1800.     gtdHaveDay = 0;
  1801.     gtdHaveRel = 0;
  1802.     gtdHaveTime = 0;
  1803.     gtdHaveZone = 0;
  1804.  
  1805.     if (gtdparse()
  1806.      || gtdHaveTime > 1 || gtdHaveZone > 1 || gtdHaveDate > 1 || gtdHaveDay > 1)
  1807.     return -1;
  1808.  
  1809.     if (gtdHaveDate || gtdHaveTime || gtdHaveDay) {
  1810.     Start = Convert(gtdMonth, gtdDay, gtdYear, gtdHour, gtdMinutes, gtdSeconds,
  1811.             gtdMeridian, gtdDSTmode);
  1812.     if (Start < 0)
  1813.         return -1;
  1814.     }
  1815.     else {
  1816.     Start = now->time;
  1817.     if (!gtdHaveRel)
  1818.         Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
  1819.     }
  1820.  
  1821.     Start += gtdRelSeconds;
  1822.     Start += RelativeMonth(Start, gtdRelMonth);
  1823.  
  1824.     if (gtdHaveDay && !gtdHaveDate) {
  1825.     tod = RelativeDate(Start, gtdDayOrdinal, gtdDayNumber);
  1826.     Start += tod;
  1827.     }
  1828.  
  1829.     /* Have to do *something* with a legitimate -1 so it's distinguishable
  1830.      * from the error return value.  (Alternately could set errno on error.) */
  1831.     return Start == -1 ? 0 : Start;
  1832. }
  1833.  
  1834.  
  1835. #if    defined(TEST)
  1836.  
  1837. /* ARGSUSED */
  1838. main(ac, av)
  1839.     int        ac;
  1840.     char    *av[];
  1841. {
  1842.     char    buff[128];
  1843.     time_t    d;
  1844.  
  1845.     (void)printf("Enter date, or blank line to exit.\n\t> ");
  1846.     (void)fflush(stdout);
  1847.     while (gets(buff) && buff[0]) {
  1848.     d = get_date(buff, (struct timeb *)NULL);
  1849.     if (d == -1)
  1850.         (void)printf("Bad format - couldn't convert.\n");
  1851.     else
  1852.         (void)printf("%s", ctime(&d));
  1853.     (void)printf("\t> ");
  1854.     (void)fflush(stdout);
  1855.     }
  1856.     exit(0);
  1857.     /* NOTREACHED */
  1858. }
  1859. #endif    /* defined(TEST) */
  1860.